﻿#ifndef OEASYPROXY_H
#define OEASYPROXY_H

#ifndef NO_WIDGETS
#include <QMainWindow>
#include <QCloseEvent>
#include <QTextEdit>
#endif
#include <QTimer>
#include <QObject>
#include "oeasycommon.h"
#include "configfile.h"
#include "access.h"
#include "ipc.h"
#include "targetcli.h"
#include "intercom.h"
#include "intercomProxy.h"
#include "uploadOpenDoorInforThread.h"
#include "settings.h"

#ifdef __linux
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#endif



#ifndef NO_WIDGETS
namespace Ui {
class OeasyProxy;
}
#endif


#ifndef NO_WIDGETS
class OeasyProxy : public QMainWindow
#else
class OeasyProxy : public QObject
#endif
{
    Q_OBJECT

public:
#ifndef NO_WIDGETS
    explicit OeasyProxy(QWidget *parent = 0);
#else
    explicit OeasyProxy(QObject *parent = 0);
#endif
    ~OeasyProxy();
private:
    void createRecordFolder();
    void initSigalHanle();
private:
#ifndef NO_WIDGETS
    Ui::OeasyProxy *ui;
#endif
    QList<IPC *> m_ipcList;
    Intercom *m_intercom;
    IntercomProxy *m_intercomProxy;
    Access m_access;
    TargetCli *m_pTargetCli;
    QMap<QNetworkReply *, QPair<QByteArray, int> > m_replyMap;
    QTimer m_timer;

    Settings *m_pRecord;
    QString m_Group;
    QString m_strRecordDirPath;
    QThread* m_pManageThreadUploadInfor;
    uploadOpenDoorInforThread* m_pUploadInforThread;


    void initIpc();
    void initLog();
    void httpOperate(QNetworkRequest, QNetworkAccessManager::Operation, const QPair<QByteArray, int> &);
    void initUploadOpenDoorInfor();
    void cleanupUploadOpenDoorInfor();

signals:
    void snapAndGetVideo(const QString data,int channel,LONG lRealPlayHandle);
    void sigInitPara(TRANSFER_INFO);
public slots:
    void onLogChanged();
    void onPostTmpPic(const QByteArray &);
    void onPostPic(const QByteArray &);
    void onPostReport(const QByteArray &);
    void onPostBigData(const QByteArray &);
    void onPostFinish(QNetworkReply *r);
    void onTimeout();
    void onOpenDoor(QByteArray data);
#ifndef NO_WIDGETS
   // void closeEvent(QCloseEvent *event);

#endif
};

#endif // OEASYPROXY_H
